package July;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class Test09LocalDate {
    public static void main(String[] args) throws ParseException {
        //计算你活了多少天
        survival("2001-08-28");

        survival(LocalDate.of(2001, 8, 28), LocalDate.now());

        leapYear(LocalDate.of(2000,1,1));



    }


    //jdk7写法
    public static void survival(String birthday) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse(birthday);
        long birthdayTime = date.getTime();
        long todayTime = System.currentTimeMillis();
        long time = todayTime - birthdayTime;
        System.out.println(time / 1000 / 60 / 60 / 24);


    }


    //jdk8写法
    public static void survival(LocalDate birthday, LocalDate today) {
        System.out.println(ChronoUnit.DAYS.between(birthday, today));
    }

    //判断是否是平年
    public static void leapYear(LocalDate year) {
        if(year.isLeapYear()){
            System.out.println(year.getYear()+"年是平年");
        }else {
            System.out.println(year.getYear()+"年是闰年");
        }


    }
}
